package com.example.controller;

import com.example.base.response.Result;
import com.example.entity.Notice;
import com.example.entity.Params;
import com.example.service.NoticeService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@Api(tags = "公告信息管理")
@CrossOrigin
@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    @PostMapping
    public Result add(@RequestBody Notice notice) {
        noticeService.add(notice);
        return Result.success();
    }

    @GetMapping("/search")
    public Result findBySearch(Params params) {
        PageInfo<Notice> info = noticeService.findBySearch(params);
        return Result.success(info);
    }

    @GetMapping("/searchTop")
    public Result findTop() {
        List<Notice> list = noticeService.findTop();
        return Result.success(list);

    }

    @DeleteMapping("/{id}")

    public Result delete(@PathVariable Integer id) {

        noticeService.delete(id);
        return Result.success();
    }


}
